<?php
include("includes/_config.php");
include("includes/_functions.php");
$func=new func;
function link_seo($type,$id){
	global $conf;
	/*
	switch($type){
		case "main" 		: 
		if($p) $link=$conf['web_url']."/?act=main&sub=".$id."&p=".$p;
		else  $link=$conf['web_url']."/?act=main&sub=".$id;
		break;
		case "cat" 		: 
			if($p) $link=$conf['web_url']."/cat/".$id."/page/".$p."/";
			else  $link=$conf['web_url']."/cat/".$id."/";
			break;
		case "song" 	: $link=$conf['web_url']."/song/".$id."/"; break;
		case "album"	:
			if($p) $link=$conf['web_url']."/album/".$id."/page/".$p."/";
			else  $link=$conf['web_url']."/album/".$id."/";
			break;
		case "movie"	: $link=$conf['web_url']."/movie/".$id."/"; break;	
		case "playlist"	: $link=$conf['web_url']."/playlist/".$id."/"; break;	
		case "singer"	:
			if($p) $link=$conf['web_url']."/singer/".$id."/page/".$p."/";
			else  $link=$conf['web_url']."/singer/".$id."/";
			break;
		case "user" 	: $link=$conf['web_url']."/user/".$id."/"; break;	
		case "user_log" 	: $link=$conf['web_url']."/?act=user&sub=".$id; break;	
		case "tivi" 	: $link=$conf['web_url']."/tivi/"; break;	
		case "do" 	: $link=$conf['web_url']."/?do=".$id; break;
		case "register"	: $link=$conf['web_url']."/register"."/"; break;	
		case "add_playlist"	: $link=$conf['web_url']."/playlist/add/"; break;					
	}
*/
	switch($type){
		case "main" 		: 
			if($p) $link=$conf['web_url']."/?act=main&sub=".$id."&p=".$p;
			else  $link=$conf['web_url']."/?act=main&sub=".$id;
			break;
		case "search" 		: 
			if($p) $link=$conf['web_url']."/?act=search&id=".$id."&p=".$p."&keyword=".$name;
			else  $link=$conf['web_url']."/?act=search&id=".$id."&keyword=".$name;
			break;
		case "cat" 		: 
			if($p) $link=$conf['web_url']."/?act=cat&id=".$id."&p=".$p;
			else  $link=$conf['web_url']."/?act=cat&id=".$id;
			break;
		case "song" 	: $link=$conf['web_url']."/?act=song&id=".$id; break;
		case "album"	:
			if($p) $link=$conf['web_url']."/?act=album&id=".$id."&p=".$p;
			else  $link=$conf['web_url']."/?act=album&id=".$id;
			break;
		case "movie"	: $link=$conf['web_url']."/?act=movie&id=".$id; break;	
		case "movie_epi"	: $link=$conf['web_url']."/?act=movie&id=".$id."&p=".$p; break;	
		case "moviefull"	: $link=$conf['web_url']."/?act=moviefull&id=".$id; break;	
		case "playlist"	: $link=$conf['web_url']."/?act=playlist&id=".$id; break;	
		case "singer"	:
			if($p) $link=$conf['web_url']."/?act=singer&id=".$id."&p=".$p;
			else  $link=$conf['web_url']."/?act=singer&id=".$id;
			break;
		case "user" 	:
			if($p) $link=$conf['web_url']."/?act=user&id=".$id."&p=".$p;
			else  $link=$conf['web_url']."/?act=user&id=".$id;
		break;	
		case "user_log" 	: $link=$conf['web_url']."/?act=user&sub=".$id; break;	
		case "do" 	: $link=$conf['web_url']."/?do=".$id; break;
		case "tivi" 	: $link=$conf['web_url']."/?act=tivi"; break;	
		case "register"	: $link=$conf['web_url']."/?act=register"; break;	
		case "add_playlist"	: $link=$conf['web_url']."/?act=playlist&sub=add"; break;		
		case "mtv"	: $link=$conf['web_url']."/?act=mtv"; break;				
		case "video"	: 
				if($p) $link=$conf['web_url']."/?act=video&p=".$p;
				else  $link=$conf['web_url']."/?act=video";
				break;
	}
	return $link;

}
	// PHP google_sitemap Generator

class google_sitemap
{
  var $header = "<\x3Fxml version=\"1.0\" encoding=\"UTF-8\"\x3F>\n\t<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">
";
  var $charset = "UTF-8";
  var $footer = "\t</urlset>\n";
  var $items = array();

  /** Adds a new item to the channel contents.
   *@param google_sitemap item $new_item
   *@access public
   */
  function add_item($new_item){
    //Make sure $new_item is an 'google_sitemap item' object
    if(!is_a($new_item, "google_sitemap_item")){
      //Stop execution with an error message
      trigger_error("Can't add a non-google_sitemap_item object to the sitemap items array");
    }
    $this->items[] = $new_item;
  }

  /** Generates the sitemap XML data based on object properties.
   *@param string $file_name ( optional ) if file name is supplied the XML data is saved in it otherwise returned as a string.
   *@access public
   *@return [void|string]
   */
  function build( $file_name = null )
  {
    $map = $this->header . "\n";

    foreach($this->items as $item)
    {
		//$item->loc = htmlentities($item->loc, ENT_QUOTES);
      $map .= "\t\t<url>\n\t\t\t<loc><![CDATA[$item->loc]]></loc>\n";

	  // lastmod
      if ( !empty( $item->lastmod ) )
      	$map .= "\t\t\t<lastmod><![CDATA[$item->lastmod]]></lastmod>\n";

	  // changefreq
      if ( !empty( $item->changefreq ) )
      	$map .= "\t\t\t<changefreq><![CDATA[$item->changefreq]]></changefreq>\n";

	  // priority
      if ( !empty( $item->priority ) )
      	$map .= "\t\t\t<priority><![CDATA[$item->priority]]></priority>\n";

      $map .= "\t\t</url>\n\n";
    }

    $map .= $this->footer . "\n";

    if(!is_null($file_name)){
      $fh = fopen($file_name, 'w');
      fwrite($fh, $map);
      fclose($fh);
    }else{
      return $map;
    }
  }

}

/** A class for storing google_sitemap items and will be added to google_sitemap objects.
 *@author Svetoslav Marinov <svetoslav.marinov@gmail.com>
 *@copyright 2005
 *@access public
 *@package google_sitemap_item
 *@link http://devquickref.com
 *@version 0.1
*/
class google_sitemap_item
{
  /** Assigns constructor parameters to their corresponding object properties.
   *@access public
   *@param string $loc location
   *@param string $lastmod date (optional) format in YYYY-MM-DD or in "ISO 8601" format
   *@param string $changefreq (optional)( always,hourly,daily,weekly,monthly,yearly,never )
   *@param string $priority (optional) current link's priority ( 0.0-1.0 )
   */
  function google_sitemap_item( $loc, $lastmod = '', $changefreq = '', $priority = '' )
  {
    $this->loc = $loc;
    $this->lastmod = $lastmod;
    $this->changefreq = $changefreq;
    $this->priority = $priority;
  }
}


	$cats[] = array(
						"loc" => $conf['web_url'],
						"changefreq" => "weekly",
						"priority"	=> 	"0.5",
					);

					
	// these day may be retrieved from DB
$qcat=$DB->query("select * from ".$conf['prefix']."cat order by cat_id desc");	

while($r=$DB->fetch_row($qcat)){	
	$cats[] = array(
						"loc" => link_seo('cat',$r['cat_id']),
						"changefreq" => "weekly",
						"priority"	=> 	"0.2",
					);

}	
	
$qr=$DB->query("select * from ".$conf['prefix']."multimedia order by multi_id desc");
while($ro=$DB->fetch_row($qr)){	
$multi_type=$ro['multi_type']==1?"album":"movie";
$link_multi=link_seo($multi_type,$ro['multi_id']);
	$cats[] = array(
						"loc" => $link_multi,
						"changefreq" => "daily",
						"priority"	=> 	"0.6",
					);

}

$qry=$DB->query("select * from ".$conf['prefix']."media where m_multimedia=0 OR m_multimedia in(select multi_id from ".$conf['prefix']."multimedia where multi_type=1) order by m_id desc");
while($ju=$DB->fetch_row($qry)){	
$link_media= link_seo("song",$ju['m_id']);
	$cats[] = array(
						"loc" => $link_media,
						"changefreq" => "hourly",
						"priority"	=> 	"0.5",
					);

}
	$site_map_container =& new google_sitemap();

	for ( $i=0; $i < count( $cats ); $i++ )
	{
		$value = $cats[ $i ];

		$site_map_item =& new google_sitemap_item( $value[ 'loc' ], "", $value[ 'changefreq' ], $value[ 'priority' ] );

		$site_map_container->add_item( $site_map_item );
	}

	header( "Content-type: application/xml; charset=\"".$site_map_container->charset . "\"", true );
	header( 'Pragma: no-cache' );

	print $site_map_container->build();


?>